<template>
    <div>
    <van-nav-bar class="app-nav-bar" title="异常处理修改" left-arrow @click-left="onClickLeft"/>
        <el-form label-width="80px"  :model="form">
            <el-form-item label="检查日期:">
                <el-date-picker
                    v-model="currentDate"
                    type="date"
                    value-format="yyyy-MM-dd"
                    placeholder="选择日期">
                </el-date-picker>
                <!-- {{tableData.checkDate}} -->
            </el-form-item>
            <el-form-item label="宿舍:">
                {{tableData.dorAddress}}
            </el-form-item>
             <el-form-item label="卫生项:">
                <el-select v-model="classContent" multiple placeholder="请选择">
                        <el-option
                        v-for="item in classList"
                        :key="item.id"
                        :label="item.name"
                        :value="item.id">
                        </el-option>
                    </el-select>
            </el-form-item>
            <el-form-item label="描述信息:">
                <el-input
                    type="textarea"
                    :rows="2"
                    placeholder="请输入内容"
                    v-model="form.leaveReason">
                </el-input>
            </el-form-item>
            <el-button type="success" @click="onSubmit">提交</el-button>
        </el-form>
  </div>
</template>

<script>
export default {
// app/Hygiene/getHygieneById?id=45
data(){
        return{
            minDate: new Date(2000, 0, 1),
            maxDate: new Date(2021, 10, 1),
            currentDate:'',
           form:{
               studentNo: '',
                classId: '',
                className: "",
                studentName: '',
                leaveType: '',
                leaveReason: ''
           },
           tableData:[],
            status:[],
            statusListShare:false,
            statusContent:"",
            classList:[],
            classListShare:false,
            classContent:[],
             bdormitoryId:null,
             buildingNo:'',
             storey:'',
              bdormitory:[],
             buildingNoList:[],
             storeyList:[]
        }
    },
    methods:{
        onClickLeft(){
            this.$router.go(-1) 
        },
        async onSubmit(){
            var {data:res} = await this.request({
                url:this.$location.editHygiene,
                method:'post',
                data:{
                    bdormitoryId: 10,
                    buildingNo: null,
                    checkDate: this.currentDate,
                    createBy: this.tableData.createBy,
                    createById: null,
                    createTime: this.tableData.createTime,
                    deductIds: this.classContent,
                    deductOptions: this.tableData.deductOptions,
                    dorAddress: this.tableData.dorAddress,
                    dormitoryNo: null,
                    id: this.$route.params.id,
                    modifyTime: null,
                    remark: this.form.leaveReason,
                    storey: null,
                    totalPdeduct: this.tableData.totalPdeduct,
                    totalScore:  this.tableData.totalScore
                }
            })
            console.log(res)
            if(res.status==200){
                 this.$toast.success(res.msg)
                 this.$router.push('/Hygiene');
            }
        },
        async getUser(){
            var {data:res} =await this.request({
                url:this.$location.getHygieneById,
                params:{
                    id:this.$route.params.id
                }
            })
           this.tableData=res.data;
           this.currentDate=res.data.checkDate
           this.classContent=res.data.deductIds
           this.form.leaveReason=res.data.remark
        },
        async getClassListAll(){
            const {data:res} =await this.request({url:this.$location.getHyDeAll});
            res.data.forEach(item=>{
                this.classList.push({
                    id:item.id,
                    name:item.deductOption
                })
            })
        },
    },
    created(){
        this.getUser();
        this.getClassListAll();
    }
}
</script>

<style lang="less" scoped>
.van-cell-group{
    margin: 5% 10%;
    .van-form {
        margin: 0;
    }
}
.van-cell::after {
    border-bottom:0
}
.el-textarea {
    width: 81%; 
}
</style>